package com.damie.utils;

import lombok.Data;

import java.io.Serializable;

/**
 * 返回参数
 */
@Data
public class Result<T> implements Serializable {

    private boolean success;//是否成功

    private StatusCode code;//响应状态码

    private String message;//返回消息

    private T data;//返回数据

    public Result() {
    }

    public Result(boolean success, StatusCode code, String message, Object data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = (T) data;
    }

    public Result(boolean success, StatusCode code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }

    public static Result success(){
        return success(null);
    }

    public static Result success(Object data){

        return new Result(true, StatusCode.SUCCESS,"执行成功",data);
    }

    public static Result fail(String message){

        return new Result(false, StatusCode.ERROR,"服务器异常",null);
    }
}
